﻿using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace Sustainalytics.ESG.Entities
{
    public class RPCorporateScore : IEquatable<RPCorporateScore>
    {
        public Guid CompanyId { get; set; }

        public string CompanyName { get; set; }

        public int Rank { get; set; }

        [BsonRepresentation(BsonType.Double, AllowTruncation = true)]
        public double Score { get; set; }

        public static bool operator !=(RPCorporateScore left, RPCorporateScore right)
        {
            return !Equals(left, right);
        }

        public static bool operator ==(RPCorporateScore left, RPCorporateScore right)
        {
            return Equals(left, right);
        }

        public bool Equals(RPCorporateScore other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return CompanyId.Equals(other.CompanyId) && Score.Equals(other.Score) && string.Equals(CompanyName, other.CompanyName) && Rank == other.Rank;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != GetType())
            {
                return false;
            }

            return Equals((RPCorporateScore)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = CompanyId.GetHashCode();
                hashCode = (hashCode * 397) ^ Score.GetHashCode();
                hashCode = (hashCode * 397) ^ (CompanyName != null ? CompanyName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Rank;
                return hashCode;
            }
        }
    }
}
